/*
 * Name: Minh-Tuan ta
 */

package data;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import beans.*;

public class AlbumDB extends ContentDB {
	public static synchronized ArrayList<Album> getAlbumsOfUser(int userID)
	{
		return convertContentsToAlbums(getContentsOfUserAndType(userID, ContentTypeDB.getContentTypeID("Album")));
	}
	
	public static synchronized Album getAlbum(int albumID)
	{
		return convertContentToAlbum(getContent(albumID));
	}
	
	public static synchronized int createAlbum(Album album)
	{
		return addContent(album);
	}
	
	public static synchronized int updateAlbum(Album album)
	{
		return updateContent(album);
	}
	
	public static synchronized int deleteAlbum(Album album, HttpServletRequest request)
	{
		album = getAlbum(album.getContentID());
		
		//delete the photos
		for (int i = 0; i < album.getPhotos().size(); i++)
		{
			PhotoDB.deletePhoto(album.getPhotos().get(i), request);
		}
		
		return deleteContent(album);
	}
}
